package xin.yangshuai.springsecurity03.textmessage;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

/**
 * TextMessageAuthenticationToken
 *
 * @author shuai
 * @date 2025/10/10
 */
public class TextMessageAuthenticationToken extends AbstractAuthenticationToken {

    private static final long serialVersionUID = 620L;

    private final Object principal;

    private Object credentials;

    public TextMessageAuthenticationToken(Object principal, Object credentials) {
        super((Collection) null);
        this.principal = principal;
        this.credentials = credentials;
        this.setAuthenticated(false);
    }

    public TextMessageAuthenticationToken(Object principal, Object credentials, Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        this.principal = principal;
        this.credentials = credentials;
        super.setAuthenticated(true);
    }

    public static TextMessageAuthenticationToken unauthenticated(Object principal, Object credentials) {
        return new TextMessageAuthenticationToken(principal, credentials);
    }

    public static TextMessageAuthenticationToken authenticated(Object principal, Object credentials, Collection<? extends GrantedAuthority> authorities) {
        return new TextMessageAuthenticationToken(principal, credentials, authorities);
    }

    @Override
    public Object getCredentials() {
        return this.credentials;
    }

    @Override
    public Object getPrincipal() {
        return this.principal;
    }
}
